class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int n = nums.size();
        vector<int> dp(n + 1);
        int ret = -0x3f3f3f3f;
        for (int i = 1; i <= n; i++)
        {
            dp[i] = max(dp[i - 1] + nums[i - 1], nums[i - 1]);
            ret = max(ret, dp[i]);
        }
        return ret;
    }
};

class Solution {
public:
    vector<int> productExceptSelf(vector<int>& nums) {
        int n = nums.size();
        vector<int> prev(n);
        vector<int> suffix(n);
        prev[0] = suffix[n - 1] = 1;
        vector<int> ret(n);
        for (int i = 1; i < n; i++) prev[i] = prev[i - 1] * nums[i - 1];
        for (int i = n - 2; i >= 0; i--) suffix[i] = suffix[i + 1] * nums[i + 1];

        for (int i = 0; i < n; i++)
        {
            ret[i] = prev[i] * suffix[i];
        }
        return ret;
    }
};